﻿@using UsedBookTradeSystem.Models.Entity;
@using UsedBookTradeSystem.Models.Enum;
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_BackLayout.cshtml";
    int index = 0;
}
<div class="container-fluid flex-grow-1 container-p-y">
    <h4 class="font-weight-bold py-3 mb-0">订单管理</h4>

    <div class="card">
        <div class="card-header">
            <p style="display:inline;vertical-align:middle">订单列表</p>
        </div>
        <table class="table card-table">
            <thead class="thead-light">
                <tr>
                    <th>#</th>
                    <th>订单状态</th>
                    <th>收货地址</th>
                    <th>收货人</th>
                    <th>联系电话</th>
                    <th>总价</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @foreach (Order item in ViewBag.OrderList)
                {
                    index++;
                    <tr>
                        <td scope="row" style="vertical-align:middle">@index</td>
                        <td style="vertical-align:middle">
                            @(
                                item.OrderStatus switch
                                {
                                    OrderEnum.paid => "待发货",
                                    OrderEnum.Delivery => "已发货",
                                    OrderEnum.Completed => "已完成",
                                    OrderEnum.Cancel => "已取消",
                                    _=>"未知状态"
                                }
                            )</td>
                        <td style="vertical-align:middle">@item.Address</td>
                        <td style="vertical-align:middle">@item.UserName</td>
                        <td style="vertical-align:middle">@item.Tel</td>
                        <td style="vertical-align:middle">￥@item.Total</td>
                        <td style="vertical-align:middle">
                            @Html.ActionLink("查看", "Detail", new { id = item.Id }, new { @class = "btn btn-success deleteBtn" })
                            @(
                                item.OrderStatus switch
                                {
                                    OrderEnum.paid => Html.ActionLink("发货", "ChangeStatus", new { id = item.Id,status=item.OrderStatus }, new { @class = "btn btn-success deleteBtn" }),
                                    OrderEnum.Delivery => Html.ActionLink("完成订单", "ChangeStatus", new { id = item.Id, status = item.OrderStatus }, new { @class = "btn btn-success deleteBtn" }),
                                    OrderEnum.Completed => null,
                                    OrderEnum.Cancel => null,
                                    _ => null
                                }
                                )
                        </td>
                    </tr>
                }
                @if (index == 0)
                {
                    <tr>
                        <td colspan="4" style="vertical-align:central;text-align:center;"> 暂无数据 </td>
                    </tr>

                }
            </tbody>
        </table>
        
    </div>
</div>

